package leetcode.code1442;

import java.util.HashMap;
import java.util.Map;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int countTriplets(int[] arr) {
		int len = arr.length;
		int[] sums = new int[len];
		sums[0] = arr[0];
		for (int i = 1; i < len; i++) {
			sums[i] = arr[i] ^ sums[i - 1];
		}
		int ans = 0;
		Map<Integer, Integer> map = new HashMap<>();
		map.put(0, 1);
		for (int j = 1; j < len; j++) {
			for (int k = j; k < len; k++) {
				ans += map.getOrDefault(sums[k], 0);
			}
			map.put(sums[j - 1], map.getOrDefault(sums[j - 1], 0) + 1);
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(4, this.countTriplets(H.str2array3("[2,3,1,6,7]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
